%{
  #include <stdio.h>
  #include <string.h>
  #include "TreeNode.h"
  #include "syntax.tab.h"

  int syntax_error=0;
  //still have some problems to identify float in this part
%}

%option yylineno

int_dec (0|[1-9][0-9]*)
int_oct (0[0-7]+)
int_hex (0[xX][0-9a-fA-F]+)
int ({int_dec}|{int_oct}|{int_hex})

float ([0-9]+\.[0-9]+)

id ([_a-zA-Z][_0-9a-zA-Z]*)

relop ">"|"<"|">="|"<="|"=="|"!="

ws [ \t\v\n\r]+

%%

{int} {yylval.type_node=createNode("INT",yytext);return INT;}
{float} {yylval.type_node=createNode("FLOAT",yytext);return FLOAT;}
";" {yylval.type_node=createNode("SEMI",yytext);return SEMI;}
"," {yylval.type_node=createNode("COMMA",yytext);return COMMA;}
"=" {yylval.type_node=createNode("ASSIGNOP",yytext);return ASSIGNOP;}
{relop} {yylval.type_node=createNode("RELOP",yytext);return RELOP;}
"+" {yylval.type_node=createNode("PLUS",yytext);return PLUS;}
"-" {yylval.type_node=createNode("MINUS",yytext);return MINUS;}
"*" {yylval.type_node=createNode("STAR",yytext);return STAR;}
"/" {yylval.type_node=createNode("DIV",yytext);return DIV;}
"&&" {yylval.type_node=createNode("AND",yytext);return AND;}
"||" {yylval.type_node=createNode("OR",yytext);return OR;}
"." {yylval.type_node=createNode("DOT",yytext);return DOT;}
"!" {yylval.type_node=createNode("NOT",yytext);return NOT;}
"(" {yylval.type_node=createNode("LP",yytext);return LP;}
")" {yylval.type_node=createNode("RP",yytext);return RP;}
"[" {yylval.type_node=createNode("LB",yytext);return LB;}
"]" {yylval.type_node=createNode("RB",yytext);return RB;}
"{" {yylval.type_node=createNode("LC",yytext);return LC;}
"}" {yylval.type_node=createNode("RC",yytext);return RC;}
int|float {yylval.type_node=createNode("TYPE",yytext);return TYPE;}
struct {yylval.type_node=createNode("STRUCT",yytext);return STRUCT;}
return {yylval.type_node=createNode("RETURN",yytext);return RETURN;}
if {yylval.type_node=createNode("IF",yytext);return IF;}
else {yylval.type_node=createNode("ELSE",yytext);return ELSE;}
while {yylval.type_node=createNode("WHILE",yytext);return WHILE;}
{id} {yylval.type_node=createNode("ID",yytext);return ID;}
{ws}+ {}
. {printf("Error type A at Line %d: Mysterious characters \'%s\'\n",yylineno,yytext);syntax_error++;}

%%

